using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace OraHRDAO
{
	///<summary>
	/// DAO Class for the DEPARTMENTS table.
	///</summary>
	public class DEPARTMENTS : Entity
	{
		private Int32 _DEPARTMENT_ID;
		private String _DEPARTMENT_NAME;
		private Int32 _MANAGER_ID;
		private Int32 _LOCATION_ID;
	
		///Default constructor
		public DEPARTMENTS ()
		{
		
		}

        /// <summary>
        /// Constructor for joins. 
		/// Available CHILD tables to join with:
		///    - EMPLOYEES ( EMPLOYEES_EMP_DEPT_FK )
		///    - JOB_HISTORY ( JOB_HISTORY_JHIST_DEPT_FK )
		/// Available PARENT tables to join with:
		///    - LOCATIONS
		///    - EMPLOYEES
        /// </summary>
        public DEPARTMENTS(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}

		///Constructor for Joins with flat hierarchy
        public DEPARTMENTS(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		///<summary>
		/// Property for column DEPARTMENT_ID.
		///</summary>
		[IsNotNullable]
		[IsPK]
		public Int32 DEPARTMENT_ID
		{
			get
			{
				return _DEPARTMENT_ID;
			}
			set
			{
				_DEPARTMENT_ID = value;
			}
		}
		///<summary>
		/// Property for column DEPARTMENT_NAME.
		///</summary>
		[IsNotNullable]
		[MaxLength(30)]
		public String DEPARTMENT_NAME
		{
			get
			{
				return _DEPARTMENT_NAME;
			}
			set
			{
				_DEPARTMENT_NAME = value;
			}
		}
		///<summary>
		/// Property for column MANAGER_ID.
		///</summary>
		public Int32 MANAGER_ID
		{
			get
			{
				return _MANAGER_ID;
			}
			set
			{
				_MANAGER_ID = value;
			}
		}
		///<summary>
		/// Property for column LOCATION_ID.
		///</summary>
		public Int32 LOCATION_ID
		{
			get
			{
				return _LOCATION_ID;
			}
			set
			{
				_LOCATION_ID = value;
			}
		}
	
        #region MANAGERS 
        private EntityCollection _MANAGERS;
		///<summary>
		/// Related table MANAGERS as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(MANAGERS),"MANAGERS")]
        public EntityCollection MANAGERS
        {
            get
            {
                return _MANAGERS;
            }

            set
            {
                _MANAGERS = value;
            }
        }
        private MANAGERS _MANAGERS_;
		///<summary>
		/// Related table MANAGERS as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public MANAGERS MANAGERS_
        {
            get
            {
                return _MANAGERS_;
            }

            set
            {
                _MANAGERS_ = value;
            }
        }
        #endregion
        #region EMPLOYEES
        private EntityCollection _EMPLOYEES;
        ///<summary>
        /// Related table EMPLOYEES as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(EMPLOYEES), "EMPLOYEES")]
        public EntityCollection EMPLOYEES
        {
            get
            {
                return _EMPLOYEES;
            }

            set
            {
                _EMPLOYEES = value;
            }
        }
        private EMPLOYEES _EMPLOYEES_;
        ///<summary>
        /// Related table EMPLOYEES as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public EMPLOYEES EMPLOYEES_
        {
            get
            {
                return _EMPLOYEES_;
            }

            set
            {
                _EMPLOYEES_ = value;
            }
        }
        #endregion
	
        #region JOB_HISTORY 
        private EntityCollection _JOB_HISTORY;
		///<summary>
		/// Related table JOB_HISTORY as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(JOB_HISTORY),"JOB_HISTORY")]
        public EntityCollection JOB_HISTORY
        {
            get
            {
                return _JOB_HISTORY;
            }

            set
            {
                _JOB_HISTORY = value;
            }
        }
        private JOB_HISTORY _JOB_HISTORY_;
		///<summary>
		/// Related table JOB_HISTORY as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public JOB_HISTORY JOB_HISTORY_
        {
            get
            {
                return _JOB_HISTORY_;
            }

            set
            {
                _JOB_HISTORY_ = value;
            }
        }
        #endregion
        #region LOCATIONS 
        private EntityCollection _LOCATIONS;
		///<summary>
		/// Related table LOCATIONS as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(LOCATIONS),"LOCATIONS")]
        public EntityCollection LOCATIONS
        {
            get
            {
                return _LOCATIONS;
            }

            set
            {
                _LOCATIONS = value;
            }
        }
        private LOCATIONS _LOCATIONS_;
		///<summary>
		/// Related table LOCATIONS as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public LOCATIONS LOCATIONS_
        {
            get
            {
                return _LOCATIONS_;
            }

            set
            {
                _LOCATIONS_ = value;
            }
        }
        #endregion
	    /// <summary>
	    /// Gets join for current entity and table.
	    /// </summary>
	    /// <param name="tableName">Table to join with entity.</param>
	    /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
			if (string.Compare(tableName, "EMPLOYEES", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".DEPARTMENT_ID");
				right.Add(GetType().Name + ".DEPARTMENT_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "JOB_HISTORY", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".DEPARTMENT_ID");
				right.Add(GetType().Name + ".DEPARTMENT_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
	        if (string.Compare(tableName, "LOCATIONS", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
				left.Add(tableName + ".LOCATION_ID");
				right.Add(GetType().Name + ".LOCATION_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
            if (string.Compare(tableName, "MANAGER", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
				left.Add(tableName + ".EMPLOYEE_ID");
				right.Add(GetType().Name + ".MANAGER_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			return null;
		}
	}
}


